package com.itheima.chap02;

public class StringConstructorDemo {
    public static void main(String[] args) {
//         1.自变量创建对象
        String s1 = "abc";
        System.out.println(s1);

        // 2.new String(String original)
        String s2 = new String("abc");
        System.out.println(s2);

        System.out.println(s1 == s2); // false
        // 因为当创建对象时，无论字符串常量池中有无这个字符串，new String()都会创建新的对象，所以两个对象不相等

        // 3.new String(byte[] values)
        String s3 = new String(new byte[]{97,98,99});
        System.out.println(s3);


        System.out.println(s1 == s3); // false
        System.out.println(s2 == s3); // false

        // 4.new String(char[] value)
        String s4 = new String(new char[]{'a','b','c'});
        System.out.println(s4);

        System.out.println(s1 == s4); //false
        System.out.println(s2 == s4); //false
    }

}
